{extend name="base"/}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/evaluate.css" />
<style>
    .ns-table-bottom{
        align-items: center;
    }
    .layui-form-checkbox[lay-skin=primary]{
        margin-right: 10px;
        height: 12px !important;
        width: 12px;
        min-height: 12px;
        min-width: 12px;
    }
    .layui-form-checkbox[lay-skin=primary] i{
        height: 12px;
        width: 12px;
        min-height: 12px;
        min-width: 12px;
    }
    .white_box{clear:both;}
    .ns-single-filter-box{float:right;}
    .layui-input-inline{float:left;}
</style>
{/block}
{block name="main"}
<!--<div class="layui-collapse ns-tips">-->
<!--<div class="layui-colla-item">-->
<!--<h2 class="layui-colla-title">操作提示</h2>-->
<!--<ul class="layui-colla-content layui-show">-->
<!--<li>会员购买商品之后可以针对购买的商品进行评价或者追评。</li>-->
<!--<li>商品评价之后会在前台的商品详情中进行显示。</li>-->
<!--<li>商家可以针对会员的商品评价进行回复。</li>-->
<!--</ul>-->
<!--</div>-->
<!--</div>-->

<!-- 搜索框 -->
<div class="ns-single-filter-box">
    <div class="layui-form" style="flex:1;display: flex;align-items: center; justify-content: space-between;">
        <div>
            <div class="layui-input-inline layui-hide">
                <select name="explain_type">
                    <option value="">请选择评分类型</option>
                    <option value="1">好评</option>
                    <option value="2">中评</option>
                    <option value="3">差评</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select name="scores">
                    <option value="">请选择星级</option>
                    <option value="1">一星</option>
                    <option value="2">二星</option>
                    <option value="3">三星</option>
                    <option value="4">四星</option>
                    <option value="5">五星</option>
                </select>
            </div>

            <!--<div class="layui-input-inline">
                <select name="search_type">
                    <option value="">搜索方式</option>
                    <option value="sku_name">商品名称</option>
                    <option value="member_name">评价人名称</option>
                </select>
            </div>-->

            <div class="layui-inline">
                <input type="text" name="search_text" placeholder="请输入商品名称/评价人名称" class="layui-input ns-len-mid">
                <button type="button" class="layui-btn layui-btn-primary" lay-filter="search" lay-submit>
                    <i class="layui-icon">&#xe615;</i>
                </button>
            </div>
        </div>
    </div>

</div>
<div class="white_box"></div>
<div class="ns-table-bottom layui-table-bottom-tool-temp layui-form" style="float: left;border: none; padding-left: 15px;">
    <input type="checkbox" name="check_all" lay-skin="primary" lay-filter="check_all">
    <button class="layui-btn layui-btn-primary js-audit-pass" data-is-audit="1">批量通过</button>
    <button class="layui-btn layui-btn-primary js-audit-refuse" data-is-audit="-1">批量拒绝</button>
</div>
<table class="layui-table ns-evaluate-table layui-form" lay-skin="line" lay-size="lg">
    <colgroup>
        <!-- <col width="3%"> -->
        <col width="10%">
        <col width="10%">
        <col width="8%">
        <col width="8%">
        <col width="8%">
        <col width="20%">
        <col width="15%">
        <col width="10%">
        <col width="7%">
        <col width="10%">
    </colgroup>
    <thead>
    <tr>
        <th><input style="margin-right: 10px;" type="checkbox" name="check_all" lay-skin="primary" lay-filter="check_all" />订单编号</th>
        <th>用户昵称</th>
        <th>联系方式</th>
        <th>商品评星</th>
        <th>店铺评星</th>
        <th>评论内容</th>
        <th>商品信息</th>
        <th>商户名称</th>
        <th>审核状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
<div class="ns-table-bottom layui-table-bottom-tool-temp layui-form" style="float: left;border: none; padding-left: 15px;">
    <input type="checkbox" name="check_all" lay-skin="primary" lay-filter="check_all">
    <button class="layui-btn layui-btn-primary js-audit-pass" data-is-audit="1">批量通过</button>
    <button class="layui-btn layui-btn-primary js-audit-refuse" data-is-audit="-1">批量拒绝</button>
</div>
<div id="laypage"></div>

<!-- <div class="ns-del-eval">
	<div class="layui-form">
		<input type="checkbox" name="" lay-filter="selectAllBot" lay-skin="primary">
	</div>
	<button class="layui-btn layui-btn-primary" lay-event="del">批量删除</button>
</div> -->
{/block}
{block name="script"}
<script>
    var ADMINIMG = "ADMIN_IMG";
</script>
<script src="ADMIN_JS/local_evaluate.js"></script>
<script>
    layui.use(['form', 'laydate'], function() {
        var form = layui.form,
            laydate = layui.laydate,
            currentDate = new Date(),
            minDate = "";
        form.render();

        currentDate.setDate(currentDate.getDate() - 7);

        form.on('checkbox(check_all)', function(data){
            $("input[name='evaluate']").prop("checked",data.elem.checked);
            $("input[name='check_all']").prop("checked",data.elem.checked);
            form.render();
        });

        form.on('checkbox(evaluate)', function(data){
            if($("input[name='evaluate']:checked").length == limit){
                $("input[name='check_all']").prop("checked",true);
            } else {
                $("input[name='check_all']").prop("checked",false);
            }
            form.render();
        });

        $(".js-audit-pass,.js-audit-refuse").click(function () {
            var evaluate_ids = [];
            var is_audit = $(this).attr("data-is-audit");
            $("input[name='evaluate']:checked").each(function () {
                evaluate_ids.push($(this).val());
            });

            if(evaluate_ids.length<1) {
                layer.msg("请选择要操作的数据");
                return;
            }
            modifyAuditEvaluate(evaluate_ids.toString(),is_audit);
        });

        //开始时间
        laydate.render({
            elem: '#start_time',
            type: 'datetime'
        });

        //结束时间
        laydate.render({
            elem: '#end_time',
            type: 'datetime'
        });

        /**
         * 重新渲染结束时间
         */
        function reRender() {
            $("#end_time").remove();
            $(".end-time").html('<input type="text" class="layui-input" placeholder="结束时间" name="end_time" id="end_time" >');
            laydate.render({
                elem: '#end_time',
                type: 'datetime',
                min: minDate
            });
        }

        /**
         * 搜索
         */
        form.on('submit(search)', function(data) {
            var evaluate = new Evaluate(2, [2, 4, 6]);
            evaluate.getList({
                "_this": evaluate,
                "search_type": data.field.search_type,
                "search_text": data.field.search_text,
                "explain_type": data.field.explain_type,
                "scores": data.field.scores,
                "start_time": data.field.start_time,
                "end_time": data.field.end_time,
                "goods_id" : data.field.goods_id
            });
            evaluate.pageInit({
                "_this": evaluate,
                "search_type": data.field.search_type,
                "search_text": data.field.search_text,
                "explain_type": data.field.explain_type,
                "scores": data.field.scores,
                "start_time": data.field.start_time,
                "end_time": data.field.end_time,
                "goods_id" : data.field.goods_id
            });
            return false;
        });
    });

    function replay(e) {
        var input = $(e).parents("tr").prev().find(".evaluate_id");
        var evaluate_id = input.val();
        var isFirstExplain = input.attr("data-is-first-explain");

        layer.prompt({
            formType: 2,
            value: '',
            title: '请输入回复内容',
            area: ['350px', '150px'] ,//自定义文本域宽高
            yes: function(index, layero) {
                var explain = layero.find(".layui-layer-input").val();

                if (explain) {
                    $.ajax({
                        url: ns.url("admin/goods/evaluateapply"),
                        data: {
                            evaluate_id: evaluate_id,
                            explain: explain,
                            is_first_explain: isFirstExplain
                        },
                        dataType: 'JSON', //服务器返回json格式数据
                        type: 'POST', //HTTP请求类型
                        success: function(res) {
                            layer.msg(res.message);

                            if (res.code == 0) {
                                layer.closeAll();
                                evaluate.getList({
                                    "_this": evaluate
                                });
                            }
                        }
                    });
                    layer.close(index);
                } else {
                    layer.msg('请输入回复内容!', {icon: 5, anim: 6});
                }
            }
        });
    }

    var repeat_flag = false;
    function deleteContent(e, isFirst) {
        var input = $(e).parents("tr").prev().find(".evaluate_id");
        var evaluate_id = input.val();

        if(repeat_flag) return false;
        repeat_flag = true;

        layer.confirm('确定要删除回复内容吗?', function() {
            $.ajax({
                url: ns.url("admin/goods/deleteContent"),
                data: {
                    evaluate_id: evaluate_id,
                    is_first: isFirst
                },
                dataType: 'JSON', //服务器返回json格式数据
                type: 'POST', //HTTP请求类型
                success: function(res) {
                    repeat_flag = false;

                    if (res.code == 0) {
                        evaluate.getList({
                            "_this": evaluate
                        });

                        layer.closeAll();
                    } else {
                        layer.closeAll();
                        layer.msg(res.message);
                    }
                }
            });
        }, function () {
            layer.close();
            repeat_flag = false;
        });
    }

    // 修改审核状态
    function audit(e,is_audit) {
        var input = $(e).parents("tr").prev().find(".evaluate_id");
        var evaluate_id = input.val();
        modifyAuditEvaluate(evaluate_id,is_audit);
    }

    function modifyAuditEvaluate(evaluate_ids,is_audit) {
        $.ajax({
            url: ns.url("admin/goods/modifyAuditEvaluate"),
            data: {
                evaluate_ids: evaluate_ids,
                is_audit: is_audit
            },
            dataType: 'JSON', //服务器返回json格式数据
            type: 'POST', //HTTP请求类型
            success: function (res) {
                layer.msg(res.message);
                if (res.code == 0) {
                    evaluate.getList({
                        "_this": evaluate
                    });
                }
            }
        });
    }
</script>
{/block}